package com.xy.biz.auth.controller;

import com.xy.biz.auth.domain.req.ChangePasswordRequest;
import com.xy.biz.auth.domain.req.ModifyPasswordRequest;
import com.xy.biz.auth.service.UserPasswordService;
import com.xy.lang.domain.Result;
import com.xy.lang.validation.annotation.Validatable;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/auth/pwd")
public class UserPasswordController {

    @Autowired
    private UserPasswordService userPasswordService;

    @Validatable
    @PostMapping(value = "/change")
    public Result<?> change(@RequestBody ChangePasswordRequest request) {
        userPasswordService.updateUserPassword(request.getUserId(), request.getPassword());
        return Result.success();
    }

    @ApiOperation("个人密码修改")
    @Validatable
    @PostMapping(value = "/personal_modify_password")
    public Result<?> personalPasswordModify(@RequestBody ModifyPasswordRequest request) {
        return userPasswordService.personalPasswordModify(request);
    }

}
